package cn.ycbjie.ycaudioplayer.newpack.linkagescroll.fragment;

import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;


import com.blankj.utilcode.util.ToastUtils;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;

import com.jcodecraeer.xrecyclerview.ProgressStyle;
import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.synjones.minnovate.frame.basesdk.http.SynHttp;
import com.synjones.minnovate.frame.basesdk.http.SynSchedulersTranfs;
import com.synjones.minnovate.frame.basesdk.http.exception.AbsRxSubscriber;
import com.synjones.minnovate.frame.basesdk.http.exception.ApiException;
import com.synjones.minnovate.frame.basesdk.log.SynLog;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.ycbjie.ycaudioplayer.R;
import cn.ycbjie.ycaudioplayer.base.BaseAppHelper;
import cn.ycbjie.ycaudioplayer.executor.online.PlayOnlineMusic;
import cn.ycbjie.ycaudioplayer.executor.online.PlayOnlineMusic_new;
import cn.ycbjie.ycaudioplayer.newpack.linkagescroll.MainActivity;
import cn.ycbjie.ycaudioplayer.newpack.linkagescroll.adapter.RecyclerBaseAdapter3;
import cn.ycbjie.ycaudioplayer.newpack.linkagescroll.iapiserver.iapi;
import cn.ycbjie.ycaudioplayer.newpack.linkagescroll.itemDecoration.AlphaDividerItemDecoration;
import cn.ycbjie.ycaudioplayer.newpack.linkagescroll.mybeans.MyPlayerlistBean;
import cn.ycbjie.ycaudioplayer.receiver.MyBroadcastReceiver;
import cn.ycbjie.ycaudioplayer.service.PlayService;
import cn.ycbjie.ycaudioplayer.ui.music.local.model.AudioMusic;
import cn.ycbjie.ycaudioplayer.ui.music.onLine.model.bean.OnlineMusicList;
import cn.ycbjie.ycaudioplayer.util.musicUtils.CoverLoader;

import static cn.ycbjie.ycaudioplayer.newpack.linkagescroll.config.MyConfig.baseURL;
import static cn.ycbjie.ycaudioplayer.ui.music.onLine.model.bean.OnlineMusicList.*;


/**
 * Created by shuyu on 2016/11/10.
 */

public class ListFragment extends Fragment {


    @BindView(R.id.list_item_recycler)
    XRecyclerView listItemRecycler;
    @BindView(R.id.iv_play_bar_play)
    ImageView ivPlayBarPlay;
//    @BindView(R.id.iv_play_bar_cover)
//    ImageView ivPlayBarCover;
//    @BindView(R.id.tv_play_bar_title)
//    TextView tvPlayBarTitle;
//    @BindView(R.id.tv_play_bar_artist)
//    TextView tvPlayBarArtist;
//    @BindView(R.id.iv_play_bar_play)
//    ImageView ivPlayBarPlay;
//    @BindView(R.id.pb_play_bar)
//    ProgressBar pbPlayBar;
//    com.jc

    LinearLayoutManager linearLayoutManager;

   private String ids;
    protected int devider;
    protected boolean isRefreshing;

    protected RecyclerBaseAdapter3 recyclerBaseAdapter;
    protected List<MyPlayerlistBean> dataList = new ArrayList<>();
    protected SwipeRefreshLayout swipeRefreshLayout;
    public static final String BROADCAST_ACTION = "com.example.corn";
    private BroadcastReceiver mBroadcastReceiver;

    @SuppressLint("ValidFragment")
    public ListFragment(String idss) {
        super();
        ids=idss;
    }

    /**
     * 目标项是否在最后一个可见项之后
     */
    private boolean mShouldScroll;
    /**
     * 记录目标项位置
     */
    private int mToPosition;

    /**
     * 滑动到指定位置
     */
    final ArrayList<MyPlayerlistBean> lcs = new ArrayList<MyPlayerlistBean>();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        final View view = inflater.inflate(R.layout.fragment_list, null);

       view.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
               Toast.makeText(getActivity(), "888888888888888", Toast.LENGTH_SHORT).show();
           }
       });
        mBroadcastReceiver = new MyBroadcastReceiver1();
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(BROADCAST_ACTION);
        getActivity().registerReceiver(mBroadcastReceiver, intentFilter);


        ButterKnife.bind(this, view);

        initView();
        ivPlayBarPlay.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                getPlayService().playPause();
                Toast.makeText(getActivity(), "click kjdfdsk", Toast.LENGTH_SHORT).show();
                return false;
            }
        });

        return view;
    }


    private void smoothMoveToPosition(RecyclerView mRecyclerView, final int position) {
        // 第一个可见位置
        int firstItem = mRecyclerView.getChildLayoutPosition(mRecyclerView.getChildAt(0));
        // 最后一个可见位置
        int lastItem = mRecyclerView.getChildLayoutPosition(mRecyclerView.getChildAt(mRecyclerView.getChildCount() - 1));

        if (position < firstItem) {
            // 如果跳转位置在第一个可见位置之前，就smoothScrollToPosition可以直接跳转
            mRecyclerView.smoothScrollToPosition(position);
        } else if (position <= lastItem) {
            // 跳转位置在第一个可见项之后，最后一个可见项之前
            // smoothScrollToPosition根本不会动，此时调用smoothScrollBy来滑动到指定位置
            int movePosition = position - firstItem;
            if (movePosition >= 0 && movePosition < mRecyclerView.getChildCount()) {
                int top = mRecyclerView.getChildAt(movePosition).getTop();
                mRecyclerView.smoothScrollBy(0, top);
            }
        } else {
            // 如果要跳转的位置在最后可见项之后，则先调用smoothScrollToPosition将要跳转的位置滚动到可见位置
            // 再通过onScrollStateChanged控制再次调用smoothMoveToPosition，执行上一个判断中的方法
            mRecyclerView.smoothScrollToPosition(position);
            mToPosition = position;
            mShouldScroll = true;
        }
    }


    class MyBroadcastReceiver1 extends BroadcastReceiver {
        public final String TAG = "MyBroadcastReceiver";
        public int m = 1;

        @Override
        public void onReceive(Context context, Intent intent) {
            Log.w(TAG, "intent:" + intent);
            String position = intent.getStringExtra("position");
            Log.w(TAG, "position:" + position + " m=" + m);
            m++;
            Toast.makeText(getActivity(), "click " + position + "-" + position, Toast.LENGTH_SHORT).show();
            Bundle bundle = intent.getExtras();
            playbyid(Integer.valueOf(position) + 1, false);


        }
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
    }


    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public void onPause() {
        super.onPause();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }


    public int getDevider() {
        return devider;
    }

    public void setDevider(int devider) {
        this.devider = devider;
    }

    private void initView() {
        linearLayoutManager = new LinearLayoutManager(getActivity());
        listItemRecycler.setLayoutManager(linearLayoutManager);
        listItemRecycler.addItemDecoration(new AlphaDividerItemDecoration(getDevider(), AlphaDividerItemDecoration.LIST));
        listItemRecycler.setPullRefreshEnabled(false);
        listItemRecycler.setLoadingMoreProgressStyle(ProgressStyle.SysProgress);
        listItemRecycler.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL));//分割线

        listItemRecycler.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                if (mShouldScroll) {
                    mShouldScroll = false;
                    smoothMoveToPosition(listItemRecycler, mToPosition);
                }
            }
        });


//        listItemRecycler.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
//            @Override
//            public boolean onInterceptTouchEvent(@NonNull RecyclerView recyclerView, @NonNull MotionEvent motionEvent) {
//
//                Toast.makeText(getActivity(), "点击了" + recyclerView., Toast.LENGTH_SHORT).show();
//                return false;
//            }
//
//            @Override
//            public void onTouchEvent(@NonNull RecyclerView recyclerView, @NonNull MotionEvent motionEvent) {
//
//            }
//
//            @Override
//            public void onRequestDisallowInterceptTouchEvent(boolean b) {
//
//            }
//        });

        resolveData();

//        recyclerBaseAdapter = new RecyclerBaseAdapter(getActivity(), dataList);
//        listItemRecycler.setAdapter(recyclerBaseAdapter);

        //////加载更多先屏蔽
//        listItemRecycler.setLoadingListener(new XRecyclerView.LoadingListener() {
//            @Override
//            public void onRefresh() {
//                return;
//                //使用的是外部全局刷新
//            }
//
//            @Override
//            public void onLoadMore() {
//                if (isRefreshing())
//                    return;
//                setRefreshing(true);
//                new Handler().postDelayed(new Runnable() {
//                    @Override
//                    public void run() {
//                        setRefreshing(false);
//                        resolveData();
//                        listItemRecycler.loadMoreComplete();
//                    }
//                }, 2000);
//            }
//        });
////        recyclerBaseAdapter.setOnItemClickListener(new RecyclerBaseAdapter.OnItemClickListener() {
////            @Override
////            public void onItemClick(View view, int position) {
////                Toast.makeText(getActivity(), "点击了" + position, Toast.LENGTH_SHORT).show();
////            }
////        });
//
//
        ////////加载更多先屏蔽
    }

    private void resolveData() {
//        for (int i = 0; i < 19; i++) {
//            RecyclerDataModel recyclerDataModel = new RecyclerDataModel();
//            dataList.add(recyclerDataModel);
//        }
//        if (recyclerBaseAdapter != null)
//            recyclerBaseAdapter.notifyDataSetChanged();
        String id = ids;
        String limit = "";
        String page = "1";
        getplayererlist(id, limit, page, true);
    }

    private void getplayererlist(String id, final String limit, final String page, final Boolean isfirst) {

        SynHttp.getInstance().getApi(baseURL, iapi.class).getListmp3(id, limit, page)
                .compose(SynSchedulersTranfs.<String>schedulersTransformer())
                .subscribe(new AbsRxSubscriber<String>() {
                    @Override
                    public void onRxError(ApiException ex) {
                        SynLog.file(ex.getDisplayMessage());
                    }


                    public void onNext(String weatherInfoBean) {

                        try {
                            JSONObject obj = new JSONObject(weatherInfoBean.toString());
                            String code = obj.getString("code");
                            String data = obj.getString("data");

                            JSONObject objer = new JSONObject(data);
                            JSONArray jsonArray = objer.getJSONArray("data");
                            String dataer = objer.getString("data");
                            int total = Integer.parseInt(objer.getString("total"));
                            int limit = 100;//Integer.parseInt(objer.getString("limit"));
                            int pp = total / limit + 1;
                            Gson gson = new Gson();
                            JsonParser parser = new JsonParser();
                            JsonArray Jarray = parser.parse(dataer).getAsJsonArray();
                            for (JsonElement objel : Jarray) {
                                MyPlayerlistBean cse = gson.fromJson(objel, MyPlayerlistBean.class);
                                lcs.add(cse);

                            }
                            if (isfirst) {
                                recyclerBaseAdapter = new RecyclerBaseAdapter3(getActivity(), lcs);

//                                recyclerBaseAdapter = new RecyclerBaseAdapter3(getActivity(), dataList);
                                recyclerBaseAdapter.setOnItemClickListener(new RecyclerBaseAdapter3.OnItemClickListener() {
                                    @Override
                                    public void onItemClick(View view, int position) {
                                        recyclerBaseAdapter.setDefSelect(position);
                                        TextView tv = view.findViewById(R.id.tv_playerlist_id);
                                        TextView tvpic = view.findViewById(R.id.tv_playerlist_pic);
                                        String ids = tv.getText().toString();
                                        String pic = tvpic.getText().toString();
                                        OnlineMusicList.OnlineMusic onlineMusic = new OnlineMusicList.OnlineMusic();
                                        onlineMusic.setTitle("测试数据数据");
                                        onlineMusic.setSong_id(ids);
                                        onlineMusic.setPic_big(pic);
                                        List<AudioMusic> ls = new ArrayList<AudioMusic>();

//                                        AudioMusic audioMusic = new AudioMusic();
//                                        audioMusic.setArtist("ccc");
//                                        audioMusic.setCoverPath(pic);
//                                        audioMusic.setPath("http://fdfs.xmcdn.com/group19/M00/3B/21/wKgJK1ePRjLwvXl0AAy74JiGcgw431.mp3");
//                                       ls.add(audioMusic);
//                                       getPlayService().play(audioMusic,position);
                                        playbyid(position, true);
//                                     playMusic(onlineMusic);
                                        Toast.makeText(getActivity(), "click " + position + "-" + ids, Toast.LENGTH_SHORT).show();
                                    }
                                });
//                                recyclerBaseAdapter.setOnItemLongClickListener(new RecyclerBaseAdapter3.OnItemLongClickListener() {
//                                    @Override
//                                    public void onItemLongClick(View view, int position) {
//                                        Toast.makeText(getActivity(),"long click "+position,Toast.LENGTH_SHORT).show();
//                                    }
//                                });
                                listItemRecycler.setAdapter(recyclerBaseAdapter);
                            } else {
//                                //添加数据到列表的底部
//
//                                if(pp<Integer.parseInt(page))
//                                {
//                                    //没有加载更多了
//                                    adapterlist.changeMoreState(adapterlist.NO_LOAD_MORE);
//                                }
//
//                                else
//                                {
//                                    adapterlist.addFootItem(lcs);
//
//                                    //设置回到上拉加载状态
//                                    adapterlist.changeMoreState(adapterlist.PULLUP_LOAD_MORE);
//
//
//                                    Toast.makeText(mcontext, "上拉更新了" + lcs.size() + "条数据", Toast.LENGTH_SHORT).show();
//                                }
                            }
//                            if (adapterlist==null) {
//                                dropListView = (DropListView) findViewById(R.id.list_view_id);
//                                lv.setInterface(test_musicplayer.this);//设置回调接口
//                            adapterlist = new MyFinderAdapter(mcontext, lcs);
//                                lv.setAdapter(adapterlist);
//                            }else {
//                                adapterlist.onDateChange();
//                            }

//                            adapterlist = new MyAdapter(test_musicplayer.this, lcs);
//                            lv.setInterface(test_musicplayer.this);//设置回调接口

//                            ref_finderlist.setAdapter(adapterlist);
                        } catch (Exception ex) {
                            ex.printStackTrace();
                        }
                        SynLog.file("String----->" + weatherInfoBean.toString());
                    }
                });

    }

    private void playbyid(final int position, final boolean isdian) {
        String id = lcs.get(position).getId();
        final String pic = lcs.get(position).getCover();
        final String title = lcs.get(position).getTitle();
        SynHttp.getInstance().getApi(baseURL, iapi.class).getmp3(id,"")
                .compose(SynSchedulersTranfs.<String>schedulersTransformer())
                .subscribe(new AbsRxSubscriber<String>() {
                    @Override
                    public void onRxError(ApiException ex) {
                        SynLog.file(ex.getDisplayMessage());
                    }

//                    final ArrayList<MyPlayerlistBean> lcs = new ArrayList<MyPlayerlistBean>();

                    public void onNext(String weatherInfoBean) {

                        try {
                            JSONObject obj = new JSONObject(weatherInfoBean.toString());
                            String code = obj.getString("code");
                            if("200".equalsIgnoreCase(code)) {
                                String data = obj.getString("data");

                                JSONObject objer = new JSONObject(data);

                                String uri = objer.getString("uri");
//                            JSONArray jsonArray = objer.getJSONArray("data");
//                            String dataer = objer.getString("data");
//                            int total = Integer.parseInt(objer.getString("total"));
//                            int limit = 100;//Integer.parseInt(objer.getString("limit"));
//                            int pp  = total/limit+1;
//                            Gson gson = new Gson();
//                            JsonParser parser = new JsonParser();
//                            JsonArray Jarray = parser.parse(dataer).getAsJsonArray();
//                            for (JsonElement objel : Jarray) {
//                                MyPlayerlistBean cse = gson.fromJson(objel, MyPlayerlistBean.class);
//                                lcs.add(cse);
//
//                            }

//                                recyclerBaseAdapter = new RecyclerBaseAdapter3(getActivity(), lcs);
//
////                                recyclerBaseAdapter = new RecyclerBaseAdapter3(getActivity(), dataList);
//                                recyclerBaseAdapter.setOnItemClickListener(new RecyclerBaseAdapter3.OnItemClickListener() {
//                                    @Override
//                                    public void onItemClick(View view, int position) {
//                                        recyclerBaseAdapter .setDefSelect(position);
//                                        TextView tv =  view.findViewById(R.id.tv_playerlist_id);
//                                        TextView tvpic = view.findViewById(R.id.tv_playerlist_pic);
//                                        String ids  = tv.getText().toString();
//                                        String pic = tvpic.getText().toString();
//                                        OnlineMusicList.OnlineMusic onlineMusic = new OnlineMusicList.OnlineMusic();
//                                        onlineMusic.setTitle("测试数据数据");
//                                        onlineMusic.setSong_id(ids);
//                                        onlineMusic.setPic_big(pic);
//                                        List<AudioMusic> ls = new ArrayList<AudioMusic>();
                                if (uri != null && !"".equals(uri)) {
                                    if (!isdian) {
                                        smoothMoveToPosition(listItemRecycler, Integer.valueOf(position));
                                        recyclerBaseAdapter.setDefSelect(Integer.valueOf(position));
                                    }
                                    AudioMusic audioMusic = new AudioMusic();
                                    audioMusic.setArtist(title);
                                    audioMusic.setCoverPath(pic);
                                    audioMusic.setPath(uri);
//    ls.add(audioMusic);
                                    getPlayService().play(audioMusic, position);
                                } else {
                                    getPlayService().stop();
                                    Toast.makeText(getActivity(), "没有播放权限", Toast.LENGTH_SHORT).show();
//    Toast.makeText(getActivity(), "click " + position+"-"+ids, Toast.LENGTH_SHORT).show();
                                }

//                                     playMusic(onlineMusic);
//                                        Toast.makeText(getActivity(), "click " + position+"-"+ids, Toast.LENGTH_SHORT).show();
//                                    }
//                                });
//                                listItemRecycler.setAdapter(recyclerBaseAdapter);

                            }
                            else
                            {
                                getPlayService().stop();
                                Toast.makeText(getActivity(), "没有播放权限", Toast.LENGTH_SHORT).show();
                            }
                            onChangeImpl(getPlayService().getPlayingMusic());
//                            MainActivity mainActivity = (MainActivity) getActivity();
//                            mainActivity.onChangeImpl(getPlayService().getPlayingMusic());
//
                        } catch (Exception ex) {
                            ex.printStackTrace();
                        }
                        SynLog.file("String----->" + weatherInfoBean.toString());
                    }
                });
    }

    public void onChangeImpl(AudioMusic music) {
        if (music == null) {
            return;
        }
        Bitmap cover = CoverLoader.getInstance().loadThumbnail(music);
//        ivPlayBarCover.setImageBitmap(cover);
//        tvPlayBarTitle.setText(music.getTitle());
//        tvPlayBarArtist.setText(music.getArtist());
        boolean isplaying = getPlayService().isPlaying();
        boolean ispre = getPlayService().isPreparing();
        boolean isdef = getPlayService().isDefault();

        ivPlayBarPlay.setSelected(getPlayService().isPlaying() || getPlayService().isPreparing());
        //更新进度条
//        pbPlayBar.setMax((int) music.getDuration());
//        pbPlayBar.setProgress((int) getPlayService().getCurrentPosition());


        /*点击MainActivity中的控制器，如何更新musicFragment中的mLocalMusicFragment呢？*/
//        if (mMusicFragment != null && mMusicFragment.isAdded()) {
//            mMusicFragment.onItemPlay();
//        }
    }


//    /** 当音频播放结束的时候的监听器 */
//    private MediaPlayer.OnCompletionListener mOnCompletionListener = new MediaPlayer.OnCompletionListener() {
//        /** 当音频播放结果的时候这个方法会被调用 */
//        @Override
//        public void onCompletion(MediaPlayer mp) {
//          String sss = "";
//        }
//    };

    /**
     * 获取到播放音乐的服务
     *
     * @return PlayService对象
     */
    public PlayService getPlayService() {
        PlayService playService = BaseAppHelper.get().getPlayService();
        if (playService == null) {
            throw new NullPointerException("play service is null");
        }
        return playService;
    }

    private void playMusic(OnlineMusicList.OnlineMusic onlineMusic) {
        new PlayOnlineMusic(getActivity(), onlineMusic) {
            @Override
            public void onPrepare() {

            }

            @Override
            public void onExecuteSuccess(AudioMusic music) {
                getPlayService().play(music);
//               getPlayService().
//getPlayService().getmPlayer().setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
//    @Override
//    public void onCompletion(MediaPlayer mp) {
//        AudioMusic audioMusic = new AudioMusic();
//        audioMusic.setArtist("ccc");
//        audioMusic.setCoverPath("http://img3.imgtn.bdimg.com/it/u=2249893882,1165836821&fm=26&gp=0.jpg");
//        audioMusic.setPath("http://fdfs.xmcdn.com/group19/M00/3B/21/wKgJK1ePRjLwvXl0AAy74JiGcgw431.mp3");
////        ls.add(audioMusic);
//        getPlayService().play(audioMusic);
//    }
//});
//                MediaPlayer mediaPlayer = getPlayService().next();
//                getPlayService().play();
                ToastUtils.showShort("正在播放" + music.getTitle());

            }

            @Override
            public void onExecuteFail(Exception e) {
                ToastUtils.showShort(R.string.unable_to_play);
            }

        }.execute();
    }
//    private void plays(String id)
//    {
//
//        OnlineMusicList.OnlineMusic onlineMusic = new OnlineMusicList.OnlineMusic();
//        onlineMusic.setTitle("测试数据数据");
//        onlineMusic.setSong_id(id);
//
////        SynHttp.getInstance().getApi(baseURL, iapi.class).getmp3(id)
////                .compose(SynSchedulersTranfs.<String>schedulersTransformer())
////                .subscribe(new AbsRxSubscriber<String>() {
////                    @Override
////                    public void onRxError(ApiException ex) {
////                        SynLog.file(ex.getDisplayMessage());
////                    }
////
////                    final ArrayList<MyPlayerlistBean> lcs = new ArrayList<MyPlayerlistBean>();
////
////                    public void onNext(String weatherInfoBean) {
////
////                        try {
////                            JSONObject obj = new JSONObject(weatherInfoBean.toString());
////                            String code = obj.getString("code");
////                            String data = obj.getString("data");
////                            JSONObject objs = new JSONObject(data);
////                            String uri = objs.get("uri").toString();
////                            OnlineMusicList.OnlineMusic onlineMusic = new OnlineMusicList.OnlineMusic();
////                            onlineMusic.setTitle("测试数据数据");
////                            onlineMusic.setSong_id();
////
////
////
////
////                        }
////                        catch (Exception ex)
////                        {
////                            ex.printStackTrace();
////                        }
////                    }
////                });
//    }

    /**
     * 刷新
     */
    public void refresh() {
        if (isRefreshing())
            return;
        setRefreshing(true);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                setRefreshing(false);
                if (swipeRefreshLayout != null)
                    swipeRefreshLayout.setRefreshing(false);
                dataList.clear();
                resolveData();
            }
        }, 2000);
    }

    /**
     * 回到顶部
     */
    public void changeToTop() {
        listItemRecycler.stopNestedScroll();
        linearLayoutManager.setSmoothScrollbarEnabled(true);
        linearLayoutManager.scrollToPosition(0);
    }

    public boolean isRefreshing() {
        return isRefreshing;
    }

    public void setRefreshing(boolean refreshing) {
        isRefreshing = refreshing;
    }

    public void setSwipeRefreshLayout(SwipeRefreshLayout swipeRefreshLayout) {
        this.swipeRefreshLayout = swipeRefreshLayout;
    }

    public RecyclerView getScrollableView() {
        return listItemRecycler;
    }

}
